
const url = require('url');

// -------------------------------
let urlStr = 'http://127.0.0.1:8080/sss?name=Jack&age=18&gender=boy';
// 解析url，str变成obj，可以加上第二个参数
let {pathname, query} = url.parse(urlStr, true);
console.log(`解析url的pathname: ${pathname}`);
console.log(query.name);
// 生成地址，讲obj生成str
let obj = {
  protocol: 'http',
  host: '127.0.0.1',
  port: '8081',
  search: 'job=coder'
}
let urlFormat = url.format(obj);
console.log('url格式化的结果：',urlFormat);
// url的拼接
let newUrl = url.resolve('/a/b/c/', 'd/e/f');
console.log('url拼接的结果：',newUrl);
// -------------------------------